using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.Runtime.Serialization;
using CoreData;
namespace OpenIDHostController.DataContract
{
    [DataContract]
    public class moduleContract
    {
        [DataMember]
            public long id{get;set;}
         [DataMember]
            public string name{get;set;}
         [DataMember]
            public string description{get;set;}
         [DataMember]
            public bool active{get;set;}

         public moduleContract()
        {       
                    name ="";   
                    description ="";   
        }

         public static moduleContract ToContract(module data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new moduleContract());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (moduleContract)model;
            }
            catch
            {
                return null;
            }
        }
         public static module ToCoreData(moduleContract data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new module());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (module)model;
            }
            catch
            {
                return null;
            }
        }

         public static IList<module> ToListCoreData(IList<moduleContract> data)
        {
            var list = new List<module>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new module());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((module)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
         public static IList<moduleContract> ToListConTract(IList<module> data)
        {
            var list = new List<moduleContract>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new moduleContract());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((moduleContract)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
        
    }
}
